<template>
  <section class="gift-section" v-if="!isLoading">
    <h1>Rich blogs for you to read</h1>
    <div class="gift-container">
      <div class="gift-grid">
        <!-- 左侧大图 -->
        <div class="gift-main">
          <div class="image-container">
            <a :href="`${mainGift.link}?id=${mainGift.category_id}&childId=${mainGift.id}`" class="gift-link">
              <img :src="mainGift.image" :alt="mainGift.title" class="main-image">
              <div class="gift-overlay">
                <div class="gift-text">
                  <p class="gift-subtitle">{{ mainGift.subtitle }}</p>
                  <h2 class="gift-title">{{ mainGift.title }}</h2>
                  <a :href="mainGift.link" class="explore-btn">{{ mainGift.buttonText }}</a>
                </div>
              </div>
            </a>
          </div>
        </div>

        <!-- 右侧小图网格 -->
        <div class="gift-grid-small">
          <div v-for="(item, index) in smallGifts" :key="index" class="gift-item">
            <a :href="`${item.link}?id=${item.category_id}&childId=${item.id}`" class="gift-link">
              <img :src="item.image" :alt="item.title" class="gift-image">
              <div class="gift-caption">
                <h3>{{ item.title }}</h3>
              </div>
            </a>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { getnav, getnavList, getsidebar } from '@/api/blog'
// 定义礼品项数据结构
interface GiftItem {
  image: string;
  title: string;
  link: string;
}

// 主礼品数据结构
interface MainGiftItem extends GiftItem {
  subtitle: string;
  buttonText: string;
}

// 主礼品数据
const mainGift = ref<MainGiftItem>(
  {
    // image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/GIFT_GUIDE_7f639b69-351d-451e-a843-23d941d8a5f9_940x.jpg?v=1745982004',
    // title: 'GIFT GUIDE',
    // subtitle: 'For Every Kind of Mom',
    // link: '/mother-day-gifts',
    // buttonText: 'EXPLORE'
  }
);

// 小礼品数据
const smallGifts = ref<GiftItem[]>([
  // {
  //   image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/RTL_6fd9b459-bbe7-41fa-8ecb-17d383f5372c_470x.jpg?v=1745988085',
  //   title: 'Breathe in Linen',
  //   link: '/linen-collection'
  // },
  // {
  //   image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/RBL_d69759f3-5ba9-4d97-b044-b3cf61d58671_470x.jpg?v=1745988089',
  //   title: 'Xiang Yun Silk',
  //   link: '/xiang-yun-silk'
  // },
  // {
  //   image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/RBL_d69759f3-5ba9-4d97-b044-b3cf61d58671_470x.jpg?v=1745988089',
  //   title: 'The ACC Corner',
  //   link: '/accessories'
  // },
  // {
  //   image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/RTR_4bf02934-71eb-4c4a-b489-4d5d449a9d49_470x.jpg?v=1745988086',
  //   title: 'Tweed In Thread',
  //   link: '/tweed-collection'
  // }
]);
interface MenuItem {
  id: number
  seo_title: string
  name: string
  slug: string
}
let isLoading = ref(true)
//博客导航
const getnavFn = async () => {
  isLoading.value = true
  // const data = await getnavList(0)
  // const res = data.data
  // console.log((window as any).__INITIAL_INDEX__,"阿琴的数据")
  // if (res.code === 200) {
  const res = (window as any).__INITIAL_INDEX__.homeGift
  isLoading.value = false
  if (res?.length > 0 && res[0].list?.length > 0) {
    smallGifts.value = res[0].list
      .filter((item, index) => index > 0) // 先过滤掉索引为0的项
      .map(item => ({
        image: item.thumbnail,
        title: item.title,
        link: '/blog-left-menu',
        ...item
      }))
      .slice(0, 4) // 只取前4项
    mainGift.value = {
      image: res[0].list[0].thumbnail,
      title: res[0].list[0].title,
      subtitle: res[0].list[0].subtitle,
      link: '/blog-left-menu',
      buttonText: 'EXPLORE',
      ...res[0].list[0]
    }
  }
  // }
}
getnavFn()

</script>

<style scoped lang="scss">
/* 礼品区域样式 */
.gift-section {
  padding: 50px 0 100px 0;
  // background-color: #fae3e6;
  background-image: url('https://melov-net.oss-us-west-1.aliyuncs.com/upload/20250605180838/20250605180838_68416ca62450a.webp');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  margin-bottom: 0;

  >h1{
    font-size: 34px;
    font-weight: 500;
    letter-spacing: 2px;
    margin-bottom: 30px;
    color: #000;
    text-align: center;
  }
}

.gift-container {
  max-width: 90%;
  margin: 0 auto;
  padding: 0 15px;
  max-height: 874px;
  overflow: hidden;
}

.gift-grid {
  display: flex;
  gap: 30px;
}

.gift-main {
  flex: 1.3;
  position: relative;
}

.gift-grid-small {
  flex: 1.4;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 20px;
}

.image-container {
  position: relative;
  height: 100%;
  overflow: hidden;
}

.main-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.8s ease;
}

.gift-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s ease;
}

.gift-link {
  display: block;
  position: relative;
  height: 100%;
  overflow: hidden;
}

.gift-link:hover .main-image,
.gift-link:hover .gift-image {
  transform: scale(1.05);
}

.gift-overlay {
  position: absolute;
  // bottom: 65px;
  bottom: -23%;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
}

.gift-text {
  max-width: 90%;
}

.gift-subtitle {
  font-size: 18px;
  font-weight: 400;
  margin-bottom: 12px;
  opacity: 0.9;
}

.gift-title {
  font-size: 42px;
  font-weight: 600;
  letter-spacing: 2px;
  margin-bottom: 30px;
  line-height: 48px;
}

.explore-btn {
  display: inline-block;
  padding: 10px 30px;
  border: 2px solid #fff;
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
  transition: all 0.3s ease;
}

.explore-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.gift-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  color: #fff;
  padding: 15px;
  text-align: center;
}

.gift-caption h3 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 1px;
}

.gift-item {
  position: relative;
  height: 100%;
}

/* 媒体查询 - 自适应样式 */
@media (max-width: 992px) {
  .gift-grid {
    flex-direction: column;
  }

  .gift-main {
    flex: auto;
    margin-bottom: 20px;
  }

  .gift-grid-small {
    flex: auto;
  }

  .gift-title {
    font-size: 36px;
  }

  .gift-container {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .gift-section {
    padding: 40px 0;
  }

  .gift-grid-small {
    grid-template-columns: 1fr 1fr;
  }

  .gift-subtitle {
    font-size: 16px;
  }

  .gift-title {
    font-size: 32px;
    margin-bottom: 20px;
  }

  .gift-caption h3 {
    font-size: 14px;
  }

  .explore-btn {
    padding: 8px 24px;
  }
}

@media (max-width: 576px) {
  .gift-section {
    padding: 30px 0;
  }

  .gift-grid {
    gap: 15px;
  }

  .gift-grid-small {
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }

  .gift-title {
    font-size: 28px;
  }

  .gift-subtitle {
    font-size: 14px;
  }

  .explore-btn {
    padding: 8px 24px;
    font-size: 12px;
  }

  .gift-container {
    padding: 0 10px;
  }
}

@media (max-width: 480px) {
  .gift-grid-small {
    grid-template-columns: 1fr;
  }

  .gift-title {
    font-size: 24px;
  }

  .gift-caption {
    padding: 10px;
  }

  .gift-caption h3 {
    font-size: 13px;
  }
}
</style>